#ifndef MULTIPLEXLETTER_H_INCLUDED
#define MULTIPLEXLETTER_H_INCLUDED

#include <Ape/Object.h>
#include <Ape/ShPtr.h>
#include <Ape/Uuid.h>

namespace MultiplexD {
	namespace WorkerModel {
		enum enLetterType {
			ltShutdown = 0x000,
			ltAddWorker = 0x001
		};
		
		class MultiplexLetterData : public Ape::Object {
			TYPE_NAME("MultiplexD::WorkerModel::MultiplexLetterData")
		};
		
		struct MultiplexLetter {
			int LetterType;
			Ape::Uuid SenderID;
			Ape::ShPtr<MultiplexLetterData> Data;
			
			template <class LetterData_t>
			LetterData_t* GetData() const {
				LetterData_t* data = NULL;
				try {
					data = dynamic_cast<LetterData_t*>((MultiplexLetterData*)Data);
				}
				catch (...) {
					data = NULL;
				}
				if (data)
					return data;
				throw Ape::EInvalidOperation(L"Wrong data type requested");
			}
		};
	}
}

#endif // MULTIPLEXLETTER_H_INCLUDED
